package cn.k.service.impl;

import cn.k.domain.Business;
import cn.k.mapper.BusinessMapper;
import cn.k.qo.AppointmentQueryObject;
import cn.k.qo.BusinessQueryObject;
import cn.k.qo.QueryObject;
import cn.k.service.IBusinessService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BusinessServiceImpl implements IBusinessService {
    @Autowired
    private BusinessMapper businessMapper;

    @Override
    @Transactional
    public void insert(Business business) {
         businessMapper.insert(business);
    }

    @Override
    public void delete(Long id) {
        businessMapper.deleteByPrimaryKey(id);

    }

    @Override
    @Transactional
    public void update(Business business) {
        businessMapper.updateByPrimaryKey(business);

    }

    @Override
    public Business get(Long id) {
        Business business = businessMapper.selectByPrimaryKey(id);
        return business;
    }

    @Override
    public List<Business> selectAll() {
        List<Business> businesss = businessMapper.selectAll();
        return businesss;
    }


    @Override
    public List<Business> selectForList(BusinessQueryObject qo) {
        List<Business> businesss = businessMapper.selectForList(qo);
        return businesss;
    }

    @Override
    public PageInfo<Business> query(BusinessQueryObject qo) {
        //告诉插件我们查询第几页,每页多少条
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(), "open_date desc");
        //查询当前页数据
        List<Business> businesss = businessMapper.selectForList(qo);
        return new PageInfo<>(businesss);
    }

    @Override
    public Business queryMainStore() {
        return businessMapper.queryMainStore();
    }




}
